﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RBOSS.Data;
using RBOSS.Utilities;

namespace RBOSS.Business.AdminModule
{
    public class Configration
    {
        public Nullable<decimal> MaxCreditCard;
        public int Percentage;
        private RBOSSEntities rb = new RBOSSEntities();
        public Configration getConfigration()
        {
            
            Configration r = new Configration();
            var id=rb.Settings.Max(b => b.SettingId);
            var query = rb.Settings.Where(e=>(e.SettingId==id)).Select(e => new { e.MaxCreditCard, e.Percentage }).FirstOrDefault();
          

            r.MaxCreditCard = query.MaxCreditCard;
            r.Percentage = query.Percentage;

            return r;
        }

      


        public void AddSetting(int maxCreditCard, int percentage)

        {
            var setting = new Setting
            {
                MaxCreditCard = maxCreditCard,
                Percentage = percentage,
                SettingId = rb.Settings.Max(e => e.SettingId) + 1,

            };

            rb.Settings.Add(setting);
            rb.SaveChanges();
        }
    }
}
